#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;

class Solution {
public:
    vector<vector<int>> threeSum(vector<int>& nums)
    {
        vector<vector<int>> ret;
        sort(nums.begin(), nums.end());

        int n = nums.size();
        for (int i = 0; i < n; )
        {
            int left = i + 1, right = n - 1, target = -nums[i];
            if (target < 0)
                break;
            while (left < right)
            {
                int sum = nums[left] + nums[right];
                if (sum > target)
                    --right;
                else if (sum < target)
                    ++left;
                else
                {
                    ret.push_back({ nums[i],nums[left],nums[right] });
                    ++left, --right;
                    while (left < right && nums[left] == nums[left - 1])
                        ++left;
                    while (left < right && nums[right] == nums[right + 1])
                        --right;
                }
            }
            ++i;
            while (i < n && nums[i] == nums[i - 1])
                ++i;
        }
        return ret;
    }
};

int main()
{
    vector<int> nums({ -100,-70,-60,110,120,130,160 });
    vector<vector<int>> ret = Solution().threeSum(nums);
    
    for (int i = 0; i < ret.size(); ++i)
    {
        for (int j = 0; j < ret[0].size(); ++j)
        {
            cout << ret[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}


int main1()
{
    int n;
    cin >> n;
    vector<vector<int>> ret(n, vector<int>(n));
    for (int i = 0; i < n; ++i)
    {
        ret[i][0] = 1;
        ret[i][i] = 1;
    }

    for (int i = 2; i < n; ++i)
        for (int j = 1; j <= i - 1; ++j)
            ret[i][j] = ret[i - 1][j - 1] + ret[i - 1][j];

    cout << setw(5);
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j <= i; ++j)
        {
            cout << ret[i][j] << setw(5);
        }
        cout<<endl;
    }

    return 0;
}